#pragma once
#include "Comm.h"

namespace COMM
{
	class COMM_API Process
	{
		MYLIB_NONCOPIED_CLASS(Process);
	public:
		enum { PROCESS_MAX_ARGS=64 };
		~Process();
		const char* Name() const;
		void Terminate();
		bool Join(int* exitcode=NULL);

		static Process* Execute(const char* filename, const Arguments& argv=Arguments(), const Arguments& envp=Arguments(), bool hide=false);
		static bool ExecuteSync(const char* filename, int* exitcode=NULL, const Arguments& argv=Arguments(), const Arguments& envp=Arguments(), bool hide=false);
		static bool ExecuteSystemCommand(const char* command, int* exitcode=NULL); 
		static StringList EchoSystemCommand(const char* command, int maxLineSize=1024);
#ifdef _MSC_VER
		// invoked by NT-Service to create current user session process.
		static Process* ExecuteAsUser(const char* filename, const Arguments& argv=Arguments(), int timeoutMsForUserLogin=0, bool hide=false);
		static Process* ExecuteAsAdmin(const char* filename, const Arguments& argv=Arguments(), bool hide=false);
		static bool IsAdminPrivilege();
#endif
	
	private:
		Process();
#ifdef COMM_MSVC
		PROCESS_INFORMATION m_pi;
#else
		pid_t m_child;
#endif
		String m_filename;

	};

}

